package com.example.mall.controller;

import com.example.mall.param.brands.FindByBrandsIdParam;
import com.example.mall.param.product.AddProductParam;
import com.example.mall.param.product.DeleteProductParam;
import com.example.mall.param.product.EditProductStatusParam;
import com.example.mall.param.product.ProductTypeParam;
import com.example.mall.service.ProductService;
import com.example.mall.util.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ：Dongdequan
 * @date ：Created in 2022/8/6 8:42
 * @modified By：
 */

@RestController
@RequestMapping("/product")
public class ProductController extends BaseController{

    @Autowired
    private ProductService productService;

    @PostMapping("/all/list")
    public ResultVo allList(){//HttpServletRequest request
       // String userId = (String)request.getAttribute("userId");
        return ResultVo.success(productService.allList());
    }

    @PostMapping("/type/product/list")
    public ResultVo typeByProductList(@RequestBody ProductTypeParam param){
        return ResultVo.success(productService.typeByProductList(param));
    }

    @PostMapping("/delete")
    public ResultVo deleteProduct(@RequestBody DeleteProductParam param){
        return ResultVo.success(productService.deleteProduct(param));
    }

    @PostMapping("/edit/status")
    public ResultVo editProductStatus(@RequestBody EditProductStatusParam param){
        return ResultVo.success(productService.editProductStatus(param));
    }

    @PostMapping("/add")
    public ResultVo addProduct(@RequestBody AddProductParam param){
        return ResultVo.success(productService.addProduct(param));
    }
    @PostMapping("/findByBrandsId")
    public ResultVo findByBrandsId(@RequestBody FindByBrandsIdParam param){
        return ResultVo.success(productService.findByBrandsId(param));
    }
}
